#include<bits/stdc++.h>
using namespace std;
long  long t,n,m,l,x,ans1=0,flag=0,ans2=0;
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	cin>>t;
	for(int c=0;c<t;c++){
		cin>>n>>m>>l>>x;
		long long d[n+10]={},v[n+10]={},a[n+10]={},ce[m]={},ce2[n+10]={};
		for(int i=0;i<n;i++){
			cin>>d[i]>>v[i]>>a[i];
		}
		for(int i=0;i<m;i++){
			cin>>ce[i];
		}
		for(int i=0;i<n;i++){
			flag=1;
			for(int j=m-1;j>=0;j--){
				if(ce[j]<d[i]){continue;}
				else{
					if((v[i]*v[i]+2*a[i]*(ce[j]-d[i]))>x*x){
						if(flag==1){
							flag=0;
							ans1++;
							ce2[i]=ce[j];
							break;
						}
					}
				}
			}
		}
		long long m[n+10]={},k=0,fla=0;
		for(int i=0;i<n;i++){
			if(ce2==0){continue;}
			if(a[i]<0){
				m[k]=i;
				k++;
				if(flag==1){
					for(int j=1;j<=k;j++){
						if(ce2[i]>=a[m[j]] and ce2[i]<=ce2[m[j]]){
							fla=1;
						}
					}
					if(fla!=1){
						ans2++;
						fla=0;
					}
				}
			}
		}
		cout<<ans1<<" "<<(m-1-ans2)<<endl;
		ans1=0;
		ans2=0;
	}
	
	return 0;
}
